package com.example.neo4j.controller;

import com.example.neo4j.model.Movie;
import com.example.neo4j.model.Person;
import com.example.neo4j.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class PersonController {
    @Autowired
    private PersonService personService;

    @PostMapping("/persons")
    public Person createPerson(@RequestBody Person person) {
        return personService.createPerson(person);
    }

    @PostMapping("/movies")
    public Movie createMovie(@RequestBody Movie movie) {
        return personService.createMovie(movie);
    }

    @PostMapping("/persons/{personId}/movies/{movieId}")
    public Person addMovieToPerson(@PathVariable String personId, @PathVariable String movieId) {
        return personService.addMovieToPerson(personId, movieId);
    }

    @GetMapping("/persons")
    public Iterable<Person> getAllPersons() {
        return personService.getAllPersons();
    }

    @GetMapping("/movies")
    public Iterable<Movie> getAllMovies() {
        return personService.getAllMovies();
    }
}
